package cn.lil.service;

import cn.lil.dao.UserDao;
import cn.lil.model.User;
import jakarta.servlet.RequestDispatcher;

import java.sql.SQLException;


public class UserService {
    UserDao uDao = new UserDao();
    public User login(String username, String password) {
        User user = null;
        try {
            user = uDao.selectByUsernamePassword(username, password);
            System.out.println(user);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if (user != null) {
            return user;
        }
        return null;
    }
    public boolean register(User user){
        try{
            if (uDao.isUsernameExists(user.getUsername())){
                return false;
            }
            uDao.addUser(user);
            return true;
        }catch (SQLException e){
            e.printStackTrace();
        }
        return false;
    }
    public User getUserUpdate(int id){
        try {
            User user =new User(uDao.selectUserById(id));
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return null;
    }
}
